﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;

namespace SmartControls
{
    public partial class RollupPanel : UserControl
    {
        Image down;
        Image up;

        public RollupPanel()
        {
            InitializeComponent();
            System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(RollupPanel));
            down = ((System.Drawing.Image)(resources.GetObject("pictureButton1.BackgroundImageValue")));
            up = ((System.Drawing.Image)(resources.GetObject("pictureButton1.DisabledImageValue")));
        }

        private void pictureButton1_Click(object sender, EventArgs e)
        {
            RollUp = !RollUp;
        }

        public event EventHandler RollUpChanged;
        protected virtual void OnRollUpChanged()
        {
            // Event will be null if there are no subscribers
            if (RollUpChanged != null)
                RollUpChanged(this, null);
        }
        int backupHeight;
        bool rollUp;
        public bool RollUp
        {
            get { return rollUp; }
            set
            {
                if (value != rollUp)
                {
                    if (value)
                    {
                        this.pictureButton1.BackgroundImage = up;
                        backupHeight = this.Height;
                        this.Height = 16;
                        OnRollUpChanged();
                    }
                    else
                    {
                        this.pictureButton1.BackgroundImage = down;
                        this.Height = backupHeight;
                        OnRollUpChanged();
                    }

                    rollUp = value;
                }
            }
        }
        protected override void OnPaintBackground(PaintEventArgs e)
        {
            base.OnPaintBackground(e);
            Pen pen = new Pen(Color.Black);
            e.Graphics.DrawLine(pen, 0, 8, Width - 1, 8);
            //if (!RollUp)
            //    e.Graphics.DrawLine(pen, 0, Height - 1, Width - 1, Height - 1);
        }

        public override string Text
        {
            get
            {
                return label1.Text;
            }
            set
            {
                label1.Text = value;
            }
        }

        public string DesignerText
        {
            get { return label1.Text; }
            set { label1.Text = value; }
        }

        public virtual int LabelWidth
        {
            get { return label1.Width; }
            set { label1.Width = value; }
        }
    }
}
